package crm.view.option;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

import crm.model.teacherPC.Manager;
import crm.model.teacherPC.net.Transfer;




/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FilterOption implements ActionListener {
	private static JFrame frame;
	private static JPanel contend;
	private static JButton jButton1;
	private static JTable jTable2;
	private static JButton jButton2;
	private static JPanel jPanel2;
	private static JPanel jPanel1;
	private static JTable jTable1;


	public static void show() {
		frame = new JFrame();
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.setSize(430, 346);
		frame.setLocationRelativeTo(null);


		frame.setVisible(true);
		frame.setPreferredSize(new java.awt.Dimension(430, 346));
		{
			contend = new JPanel();
			GridLayout contendLayout = new GridLayout(2, 1);
			contendLayout.setColumns(1);
			contendLayout.setHgap(5);
			contendLayout.setVgap(5);
			frame.getContentPane().add(contend, BorderLayout.CENTER);
			contend.setLayout(contendLayout);
			{
				jPanel1 = new JPanel();
				BorderLayout jPanel1Layout = new BorderLayout();
				contend.add(jPanel1);
				jPanel1.setLayout(jPanel1Layout);
				{
					jButton1 = new JButton();
					jPanel1.add(jButton1, BorderLayout.NORTH);
					jButton1.setText("add");
					jButton1.addActionListener(new FilterOption());
				}
				{
					jTable1 = new JTable();
					jPanel1.add(jTable1, BorderLayout.CENTER);
					jTable1.setModel(new OptionTableModel(Transfer.filterList));
				}
			}
			{
				jPanel2 = new JPanel();
				BorderLayout jPanel2Layout = new BorderLayout();
				jPanel2.setLayout(jPanel2Layout);
				contend.add(jPanel2);
				{
					jButton2 = new JButton();
					jPanel2.add(jButton2, BorderLayout.NORTH);
					jButton2.setText("remove");
					jButton2.addActionListener(new FilterOption());
				}
				{

					jTable2 = new JTable();
					jPanel2.add(jTable2, BorderLayout.CENTER);
					jTable2.setModel(new OptionTableModel(Manager.WindowList));
					System.out.println(Manager.WindowList);
				}
			}
		}

	}

	public void actionPerformed(ActionEvent ev) {
		if (ev.getActionCommand().equals("add")){

		}else if (ev.getActionCommand().equals("remove")){

		}

	}
}



class OptionTableModel implements TableModel{
	ArrayList filterList;
	ArrayList <Boolean>checkboxList;
	OptionTableModel(ArrayList list){
		filterList = list;
		checkboxList = new ArrayList<Boolean>();
		for(Object o: filterList){
			checkboxList.add(false);
		}
	}
	public void addTableModelListener(TableModelListener l) {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if (columnIndex == 0){
			return Boolean.class;
		}else if (columnIndex == 1){
			return String.class;
		}
		return null;
	}

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@Override
	public String getColumnName(int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return filterList.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (columnIndex == 0){
			return checkboxList.get(rowIndex);
		}else if (columnIndex == 1){
			return filterList.get(rowIndex);
		}
		return null;
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		return columnIndex == 0;
	}

	@Override
	public void removeTableModelListener(TableModelListener l) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		if (columnIndex == 0){
			checkboxList.set(rowIndex, (Boolean)aValue);
		}

	}

}